import {CHANGE_RECOMMEND_ACTION, CHANGE_BANNER_ACTION} from "./constants";
import axios from "axios";

function changeBannerAction(banner) {
    return {
        type: CHANGE_BANNER_ACTION,
        banner,
    }
}

function changeRecommendAction(recommend) {
    return {
        type: CHANGE_RECOMMEND_ACTION,
        recommend,
    }
}

// 异步操作
function fetchHomeMultiDataAction() {
    return function (dispatch, getState) {
        console.log('-----', getState().count)
        axios.get('http://123.207.32.32:8000/home/multidata').then(res => {
            const {
                data: {
                    banner: {list: bannerList = []} = {},
                    recommend: {list: recommendList = []} = {}
                } = {}
            } = res.data;
            dispatch(changeBannerAction(bannerList));
            dispatch(changeRecommendAction(recommendList))
        })
    }
}


export {
    fetchHomeMultiDataAction,
}